File System Navigation Lab

1. Manage Files Using Command-Line Tools

In this lab, you practice efficient techniques for creating and organizing files using directories, file copies, and links.

  1. Log in to your student account on server1.example.com. Begin in your home directory.

    [student@server1 ~]$ cd ~
  2. In your home directory, create three subdirectories for organizing your files into classes. Call these directories Music, Pictures, and Videos. Create all three with one command.

    [student@server1 ~]$ mkdir Music Pictures Videos
    [student@server1 ~]$ ls -l
  3. In your home directory, create sets of empty practice files to use for the remainder of this lab. If you don’t immediately recognize the intended command, use the guided solution to see and practice how the task is accomplished. Use the shell tab completion to locate and complete path names more easily.

    1. Create six files with names in the form songX.mp3.

    2. Create six files with names in the form snapX.jpg.

    3. Create six files with names in the form filmX.avi.

      In each set, replace X with the numbers 1 through 6.
      [student@server1 ~]$ touch song1.mp3 song2.mp3 song3.mp3 song4.mp3 song5.mp3 song6.mp3
      [student@server1 ~]$ touch snap1.jpg snap2.jpg snap3.jpg snap4.jpg snap5.jpg snap6.jpg
      [student@server1 ~]$ touch film1.avi film2.avi film3.avi film4.avi film5.avi film6.avi
      [student@server1 ~]$ ls -l
  4. From your home directory, move the song files into your Music subdirectory, the snapshot files into your Pictures subdirectory, and the movie files into your Videos subdirectory.

    • When distributing files from one location to many locations, first change to the directory containing the source files. Use the simplest path syntax, absolute or relative, to reach the destination for each file management task.

      [student@server1 ~]$ mv song1.mp3 song2.mp3 song3.mp3 song4.mp3 song5.mp3 song6.mp3 Music
      [student@server1 ~]$ mv snap1.jpg snap2.jpg snap3.jpg snap4.jpg snap5.jpg snap6.jpg Pictures
      [student@server1 ~]$ mv film1.avi film2.avi film3.avi film4.avi film5.avi film6.avi Videos
      [student@server1 ~]$ ls -l Music Pictures Videos
  5. In your home directory, create three more subdirectories for organizing your files into projects. Call these directories friends, family, and work. Create all three with one command.

    • You will use these directories to rearrange your files into projects.

      [student@server1 ~]$ mkdir friends family work
      [student@server1 ~]$ ls -l
  6. Collect some of the new files into the project directories for family and friends. Use as many commands as needed. You do not have to use only one command as in the example. For each project, first change to the project directory, then copy the source files into this directory. You are making copies, since you will keep the originals after giving these projects to family and friends.

    1. Copy files (all types) containing numbers 1 and 2 to the friends folder.

    2. Copy files (all types) containing numbers 3 and 4 to the family folder.

      When collecting files from multiple locations into one location, change to the directory that will contain the destination files. Use the simplest path syntax, absolute or relative, to reach the source for each file management task.
      [student@server1 ~]$ cd friends
      [student@server1 friends]$ cp ~/Music/song1.mp3 ~/Music/song2.mp3 ~/Pictures/snap1.jpg ~/Pictures/snap2.jpg ~/Videos/film1.avi ~/Videos/film2.avi .
      [student@server1 friends]$ ls -l
      [student@server1 friends]$ cd ../family
      [student@server1 family]$ cp ~/Music/song3.mp3 ~/Music/song4.mp3 ~/Pictures/snap3.jpg ~/Pictures/snap4.jpg ~/Videos/film3.avi ~/Videos/film4.avi .
      [student@server1 family]$ ls -l
  7. Create additional copies for your work project.

    [student@server1 family]$ cd ../work
    [student@server1 work]$ cp ~/Music/song5.mp3 ~/Music/song6.mp3 ~/Pictures/snap5.jpg ~/Pictures/snap6.jpg ~/Videos/film5.avi ~/Videos/film6.avi .
    [student@server1 work]$ ls -l
  8. Your projects are now done. To clean up the projects, change to your home directory and then attempt to delete both the family and friends projects with a single rmdir command.

    [student@server1 work]$ cd
    [student@server1 ~]$ rmdir family friends
    rmdir:failed to remove 'family': Directory not empty
    rmdir:failed to remove 'friends': Directory not empty
    • Using the rmdir command should fail since both directories are non-empty.

  9. Use another command that will succeed in deleting both the family and friends folders. You will be asked if you are sure that you wish to "descend into the directories" and "remove regular empty files", enter y for yes and then press Enter.

    [student@server1 ~]$ rm -r family friends
    [student@server1 ~]$ ls -l
    You can avoid having to answer yes to all of those questions by adding the f flag to the rm command to force the operation. For example rm -rf family friends would have removed all of the files and directories without asking. This can be dangerous so always use it carefully.
  10. Delete all the files in the work project, but do not delete the work directory.

    [student@server1 ~]$ cd work
    [student@server1 work]$ rm -f song5.mp3 song6.mp3 snap5.jpg snap6.jpg film5.avi film6.avi
    [student@server1 work]$ ls -l
  11. Finally, from your home directory, use the rmdir command to delete the work directory. The command should succeed now that it is empty.

    [student@server1 work]$ cd
    [student@server1 ~]$ rmdir work
    [student@server1 ~]$ ls -l

In this lab, you create hard and soft links.

  1. Log in to your server1 system as the root user with the password r3dh@t1!.

  2. Create an additional hard link /root/qmp-manual.txt and link it to the existing file /usr/share/doc/qemu-kvm/qmp-commands.txt on server1.example.com.

    [root@server1 ~]# ln /usr/share/doc/qemu-kvm/qmp-commands.txt /root/qmp-manual.txt
    1. Verify the link count on the newly created link /root/qmp-manual.txt.

      [root@server1 ~]# ls -l /root/qmp-manual.txt
      -rw-r--r--. 2 root root 63889 Nov 11 02:8 /root/qmp-manual.txt
    2. Verify the link count on the original file /usr/share/doc/qemu-kvm/qmp-commands.txt.

      [root@server1 ~]# ls -l /usr/share/doc/qemu-kvm/qmp-commands.txt
      -rw-r--r--. 2 root root 63889 Nov 11 02:8 /usr/share/doc/qemu-kvm/qmp-commands.txt
  3. Create the soft link /root/tempdir and link it to /tmp on server1.example.com.

    [root@server1 ~]# ln -s /tmp /root/tempdir
    1. Verify the newly created link with ls -l.

      [root@server1 ~]# ls -l /root
      lrwxrwxrwx. 1 root root 4 Mar 13 08:2 /root/tempdir -> /tmp